class Set:
    def __init__(self, value=[]) -> None:
        self.data = []
        self.concat(value)

    def concat(self, value):
        for x in value:
            if not x in self.data:
                self.data.append(x)

    def intersect(self, other):
        res = []
        for x in self.data:
            if x in other:
                res.append(x)
        return Set(res)

    def union(self, other):
        res = self.data[:]
        for x in other:
            if not x in self.data:
                res.append(x)
        return Set(res)

    def __len__(self): return len(self.data)               # len(self), if self

    def __getitem__(self, key):
        return self.data[key]      # self[i], self[i:j]

    def __and__(self, other): return self.intersect(other)  # self & other
    def __or__(self, other): return self.union(other)      # self | other
    def __repr__(self): return 'Set:' + repr(self.data)    # print(self),...

    def __iter__(self):
        return iter(self.data)             # for x in self,..


class MultiSet(Set):
    def intersect(self, *others):
        res = []
        for x in self:
            for other in others:
                if not x in other:
                    break
            else:
                res.append(x)
        return Set(res)

    def union(self, *others):
        res = self.data[:]
        for other in others:
            for x in other:
                if not x in res:
                    res.append(x)
        return Set(res)


if __name__ == '__main__':
    x = Set([1, 2, 3, 4])
    y = Set([3, 4, 5])
    print(x & y)
    print(x | y)

    x = Set('walker')
    print(x)
